package com.zhk.entry.mapper.impl;


import com.zhk.entry.dao.impl.BaseDao;
import com.zhk.entry.mapper.GoodsMapperService;
import com.zhk.entry.model.Goods;
import com.zhk.entry.observer.BaseObserver;

import java.sql.Connection;
import java.util.List;


/**
 * 商品操作
 */
public class GoodsMapper extends BaseObserver implements GoodsMapperService<Goods> {


    private BaseDao baseDao = new BaseDao();

    public GoodsMapper(){}
    public GoodsMapper(BaseDao baseDao)
    {
        this.baseDao = baseDao;
    }
    /**
     * 全部查询
     *
     * @return
     */
    @Override
    public List<Goods> getGoodsAll() {
        List<Goods> list = baseDao.getQuery(new Goods(),null);

        return list;
    }

    /**
     * 条件查询
     *
     * @return
     */
    @Override
    public List<Goods> getGoods(Goods goods) {
        List<Goods> list = baseDao.getQuery(goods,null);

        return list;
    }

    /**
     * 保存商品
     *
     * @param goods
     * @return
     */
    @Override
    public String saveGoods(Goods goods, Connection conn) {

        int save = baseDao.save(goods,conn);

        return save > 0 ? "保存成功" : "保存失败";
    }

    /**
     * 修改
     *
     * @param goods
     * @return
     */
    @Override
    public String updateGoods(Goods goods) {
        int update = baseDao.update(goods);
        return update > 0 ? "修改成功" : "修改失败";
    }

    /**
     * 删除用户
     *
     * @param goods
     * @return
     */
    @Override
    public String deleteUser(Goods goods) {
        int delete = baseDao.delete(goods);
        return delete > 0 ? "删除成功" : "删除失败";
    }

    @Override
    public List getQuery(Goods goods,Connection conn) {
        return null;
    }

    @Override
    public int update(Goods goods) {
        return 0;
    }

    @Override
    public int delete(Goods goods) {
        return 0;
    }

    @Override
    public int save(Goods goods, Connection conn) {
        return 0;
    }

}
